<?php
class PlantWaterAction extends SzAbstractAction
{
    protected $paramTypes = array(
        SzAbstractAction::TYPE_INT,
        SzAbstractAction::TYPE_ARRAY,//SzAbstractAction::TYPE_STRING,
        SzAbstractAction::TYPE_INT,
    );

    /**
     * 种植浇水
     * @param $userId
     * @param $gridIdArr
     * @param $reqTime
     * @return SzResponse
     * @throws SzException
     */
    public function execute($userId, $gridIdArr, $reqTime)
    {
        GameService::get()->validateMultiRequestTimeDelta($userId, $reqTime);
        $returnArr = array();
        // 验证土地是否已经被种植
        /**
         * @var PlantVoList $plantList
         * @var PlantVo $plant
         */
        $plantList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_PLANT);
        //消耗
        $cropSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_PLANT_CROP, null, true);
        $activityData = ActivityService::get()->getActivityIdAndPosition($userId,GameConst::ACTIVITY_TASK_2);
        foreach ($gridIdArr as $gridId){
            $plant = PlantService::get()->water($userId, $gridId, $reqTime,$plantList,$cropSetting,$activityData);
            if (empty($plant)){
                continue;
            }
            else{
                if (!isset($returnArr[$gridId])){
                    $returnArr[$gridId] = array(
                        'plant' => $plant,
                    );
                }
            }
        }

        return $this->buildResponse($returnArr);
    }
}